package org.mat.ipaas.ucenter.bff.admin.modules.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.api.system.SysUserAgentRestAPI;
import org.mat.ipaas.ucenter.service.dto.system.entity.SysUserAgentDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Title: Controller
 * 用户代理人设置
 */
@RestController
@RequestMapping("/sys/sysUserAgent")
@Slf4j
public class SysUserAgentController {

    @Autowired
    private SysUserAgentRestAPI sysUserAgentRestAPI;

    /**
     * 分页列表查询
     *
     * @param sysUserAgentDTO
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/list")
    public MatApiResponse<IPage<SysUserAgentDTO>> queryPageList(@SpringQueryMap SysUserAgentDTO sysUserAgentDTO,
                                                                @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        MatApiResponse<IPage<SysUserAgentDTO>> matApiResponse = sysUserAgentRestAPI.queryPageList(sysUserAgentDTO, pageNo, pageSize);
        return matApiResponse;
    }

    /**
     * 添加
     *
     * @param sysUserAgentDTO
     * @return
     */
    @PostMapping(value = "/add")
    public MatApiResponse<SysUserAgentDTO> add(@RequestBody SysUserAgentDTO sysUserAgentDTO) {
        MatApiResponse<SysUserAgentDTO> matApiResponse = sysUserAgentRestAPI.add(sysUserAgentDTO);
        return matApiResponse;
    }

    /**
     * 编辑
     *
     * @param sysUserAgentDTO
     * @return
     */
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public MatApiResponse<SysUserAgentDTO> edit(@RequestBody SysUserAgentDTO sysUserAgentDTO) {
        MatApiResponse<SysUserAgentDTO> matApiResponse = sysUserAgentRestAPI.edit(sysUserAgentDTO);
        return matApiResponse;
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @DeleteMapping(value = "/delete")
    public MatApiResponse<SysUserAgentDTO> delete(@RequestParam(name = "id", required = true) String id) {
        MatApiResponse<SysUserAgentDTO> matApiResponse = sysUserAgentRestAPI.delete(id);
        return matApiResponse;
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @DeleteMapping(value = "/deleteBatch")
    public MatApiResponse<SysUserAgentDTO> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        MatApiResponse<SysUserAgentDTO> matApiResponse = sysUserAgentRestAPI.deleteBatch(ids);
        return matApiResponse;
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/queryById")
    public MatApiResponse<SysUserAgentDTO> queryById(@RequestParam(name = "id", required = true) String id) {
        MatApiResponse<SysUserAgentDTO> matApiResponse = sysUserAgentRestAPI.queryById(id);
        return matApiResponse;
    }

    /**
     * 通过userName查询
     *
     * @param userName
     * @return
     */
    @GetMapping(value = "/queryByUserName")
    public MatApiResponse<SysUserAgentDTO> queryByUserName(@RequestParam(name = "userName", required = true) String userName) {
        MatApiResponse<SysUserAgentDTO> matApiResponse = sysUserAgentRestAPI.queryByUserName(userName);
        return matApiResponse;
    }

    /**
     * 导出excel
     *
     * @param sysUserAgentDTO
     * @param request
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(SysUserAgentDTO sysUserAgentDTO, HttpServletRequest request) {
        ModelAndView modelAndView = sysUserAgentRestAPI.exportXls(sysUserAgentDTO, request);
        return modelAndView;
    }

    /**
     * 通过excel导入数据
     *
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public MatApiResponse<?> importExcel() {
        MatApiResponse<?> matApiResponse = sysUserAgentRestAPI.importExcel();
        return matApiResponse;
    }

}
